﻿<%@ Page Title="配件中包装" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
<link href="../assets/img/validate/validate.css" rel="stylesheet">
<link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />

<style type="text/css">
.system-box .right-side {width: 100%;}
.condition, .condition-title {border-bottom: 1px solid #dfdfdd;}
.form-group label{max-width: 70px;margin-left: 15px;padding-left: 5px;padding-right: 5px;}
.col1 {
    width: 30px;
}
.col2 {
    width: 90px;
    min-width: 50px;
}
.col3 {
    width: 200px;
    min-width: 145px;
}
.col4 {
    width: 120px;
    min-width: 120px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
 <div class="system-box"> 
   <div class="right-side">
    <div class="btns-container">
    </div> 
    <div class="condition clearfix"> 
        <label style="display:inline-block;">
            <label>查询条件：</label>
            <input type="checkbox" id="search-SizeLimit" class="form-control" value="0" style="width: 15px; margin-top: 0;" />
            <label for="search-SizeLimit" style="margin-left: 0px;float: none;">未设置货号</label>     
        </label>
        <label>&nbsp;货号：</label>
        <input id="search-MaterialID" class="form-control input-w155" />
    </div> 
    <div class="right-content-box"> 
     <div class="ibox-content"> 
      <table class="footable table table-stripped table-list loadTable"> 
       <thead></thead> 
       <tbody id="pageList"></tbody> 
      </table> 
     </div> 
    </div> 
    <div class="pageControl"></div> 
   </div> 
  </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/jquery-ui-1.10.4.min.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>

    <script>
        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                rScroll();
            });

            $("#search-SizeLimit").iCheck({ checkboxClass: "icheckbox_square-green" });
            var dataList = [];

            //处理表头
            if ($('.footable thead').children().size() == 0) {
                tableControl.initThead('.footable',
                [
                    {
                        trClass: '',
                        children: [
                            { tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllPlan" />', tdId: '', tdClass: 'col1' },
                            { tdText: '类别', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'col2' },
                            { tdText: '货号', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'col3 ' },
                            { tdText: '系数', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'col4' },
                            { tdText: '无用', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' }
                        ]
                    }
                ]);
            }

            var pageList = [];
            var loadList = function () {
                var materialID = $('#search-MaterialID').val().trim();
                var sizeLimit = 0;
                if ($('#search-SizeLimit').is(':checked')) {
                    sizeLimit = 1;
                }

                pageControl.init('SKCSizeType', 'GetList', {
                    SizeLimit: sizeLimit,
                    MaterialID : materialID,
                    Page: page,
                    Size: 50,
                    needLayer: true,
                    alwaysCallBack: function () {
                        $('#pageList').empty();
                    }
                }, function (result) {
                    pageList = [];
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        if (result.data.Items.length > 0) {
                            dataList = result.data.Items;
                            result.data.Items.map(function (item, i) {
                                pageList.push(item);
                                var tempTr = {
                                    trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                                    children: [
                                        { tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" class="checkPlan" data-index="' + i + '" />', tdId: '', tdClass: 'col1' },
                                        { tdText: (item.KindName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'KindName col2 ' },
                                        { tdText: (item.MaterialID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'MaterialID col3 ' },
                                        { tdText: '', c: 0, r: 0, tdHtml: '<input type="number" class="js-qty-input form-control SizeLimit" value="' + item.SizeLimit + '" maxlength="6" />', tdId: '', tdClass: 'col4 ' },
                                        { tdText: '', c: 0, r: 0, tdHtml: '<input type="number" style="visibility:hidden;" value="" />', tdId: '', tdClass: '' }
                                    ]
                                };
                                tBody.push(tempTr);
                            });
                        }
                        rScroll();
                    }
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 13, null);
                    //选择全部插件 2017-05-03 改
                    $(".footable").icheckAll({
                        checkObj: ".checkPlan",//表格下面的选择控件对象 选择器
                        checkAllObj: "#checkAllPlan",//全选 选择器
                        clickoutBoxCheck: false,//点击行 不选中
                        checkboxMargin: "4px 0 0 0 "//上右下左
                    });
                });
            }

            //选中记录
            $('#pageList').on('click', 'tr', function () {
                var kindName = $('.KindName').val();
                var materialId = $('.MaterialID').val();
                var sizeLimit = $('#SizeLimit').val();

                console.log(kindName + "\r\n" + materialId + "\r\n" + sizeLimit + "\r\n");

                $('.footable tr').removeClass('check');
                $(this).addClass('check');
            }); 

            //查询按钮
            $('.btns-container').on('click', '#btn-search', function () {
                page = 1;
                loadList();
            });

            //保存按钮
            $('.btns-container').on('click', '#btn-save', function () {
                var isOver = false;
                var tmpList = [];
                $('.footable .checkPlan:checked').parents('tr').each(function (index, element) {
                    var index1 = $(element).find('.checkPlan').attr("data-index");
                    $.each(dataList, function (index2, element2) {
                        if (index1 == index2) {
                            var model = dataList[index2];
                            model.SizeLimit = $(element).find('.SizeLimit').val();

                            if (!isNaN(model.SizeLimit)) {
                                var i = parseInt(model.SizeLimit);
                                if (i > -1) {
                                    isOver = false;
                                } else {
                                    isOver = true;
                                }
                            } else {
                                isOver = true;
                            }
                            tmpList.push(model);
                        }
                    });
                });

                if (tmpList.length <= 0) {
                    swal("请先勾选要保存的数据", '', 'error');
                    return false;
                }

                if (isOver) {
                    swal("系数必须为大于或者等于0的数字", '', 'error');
                    return false;
                }

                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('SKCSizeType', "UpdateList",
                    {
                        list: tmpList
                    },
                    function (data) {
                        layer.closeAll('dialog');
                        if (data.Success == false) {
                            swal(data.Message, '', 'error');
                        } else {
                            swal('保存成功!', '', 'success');
                            page = 1;
                            loadList();
                        }
                    });
            });


            loadList();

            //导入
            $(document).on("click", '#importBtn', function () {
                $.ImportExcelTemplate({
                    filetype: 'SKCSIZETYPE',
                    filename: '配件中包装',
                    action: 'ImportTemplate',
                    after: function () {
                        //回调方法
                        loadList();
                    }
                });
            });

        });
    </script>
</asp:Content>

